package cn.tedu.xuecha.controller;

import cn.tedu.xuecha.entity.dto.ContentDTO;
import cn.tedu.xuecha.entity.pojo.Content;
import cn.tedu.xuecha.respone.JsonResult;
import cn.tedu.xuecha.service.ContentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

/**
 * @author coinyang
 * @date 2023/4/19 19:20
 */
@Api(tags = "内容管理")
@RestController
@RequestMapping("content")
public class ContentController {

    @Autowired
    ContentService contentService;



    @ApiOperation("内容列表")
    @GetMapping("/list")
    public JsonResult list(){
        List<Content> list = contentService.list();
        for (Content c:list) {
            System.out.println(c);
        }
        return JsonResult.ok(contentService.list());
    }

    @ApiOperation("内容文章新增")
    @PostMapping("/addNew")
    public JsonResult addContent(ContentDTO contentDTO){
        contentService.addContent(contentDTO);

        return JsonResult.ok();
    }

    @ApiOperation("内容文章修改")
    @PostMapping("/update")
    public JsonResult updateContent(ContentDTO contentDTO,Integer id){
        contentService.updateContent(contentDTO,id);

        return JsonResult.ok();
    }


    @ApiOperation("内容文章查看")
    @GetMapping("/contentView")
    public JsonResult selectView(Integer id){
        return JsonResult.ok( contentService.selectView(id));
    }

    
}
